/*
 * 	Flan.Zeng 2011-2016	http://git.oschina.net/signup?inviter=flan
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.flan.stock.activity;

import java.util.ArrayList;

import com.flan.stock.R;
import com.flan.stock.adapter.NewsFragmentAdapter;
import com.flan.stock.fragment.FragmentNavigatorA;
import com.flan.stock.fragment.FragmentNewsYw;
import com.flan.stock.view.FooterMenuView;
import com.flan.stock.view.NewsTabView;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;

/**
 * 资讯窗口界面
 * @author flan
 * @date   2015年11月6日
 */
public class NewsActivity extends FragmentActivity implements OnPageChangeListener{
	
	private NewsTabView tab_news;
	private ViewPager viewPager;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.activity_news);
		
		//初始化底部菜单控件
		FooterMenuView menu = (FooterMenuView) this.findViewById(R.id.footer_menu);
		menu.setCurrentMenu(R.id.menu_news);
		menu.setOnTouchListener(menu.new MenuOnTouchListener());
		
		viewPager = (ViewPager) this.findViewById(R.id.vp_fragment);
		viewPager.setAdapter(new NewsFragmentAdapter(getSupportFragmentManager(), createFragments()));
		viewPager.addOnPageChangeListener(this);
		
		//初始化animationTabWidget控件
		tab_news = (NewsTabView) this.findViewById(R.id.zx_title);
		tab_news.setOnClickListener(tab_news);
		tab_news.setViewPager(viewPager);	//必须在viewPager空间实例化后设置
		
		
		
	}
	
	private ArrayList<Fragment> createFragments(){
		
		ArrayList<Fragment> list = new ArrayList<>();
		
		FragmentNewsYw yw = new FragmentNewsYw();
		FragmentNavigatorA f1 = new FragmentNavigatorA(this);
		
		list.add(yw);
		list.add(f1);
		
		return list;
	}

	@Override
	public void onPageScrollStateChanged(int arg0) {
	}

	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {
	}

	@Override
	public void onPageSelected(int position) {
		if(tab_news != null){
			tab_news.setCurrentTab(position);
		}
	}
	
}










